import axios from 'axios'

export class OllamaAPI {
  constructor(baseURL) {
    this.client = axios.create({
      baseURL
    })
  }

  async testConnection() {
    try {
      const response = await this.client.get('/api/version')
      return response.data
    } catch (error) {
      throw new Error('无法连接到 Ollama 服务')
    }
  }

  async getModels() {
    const response = await this.client.get('/api/tags')
    return response.data
  }

  async chat(model, message, messages) {
    const response = await this.client.post('/api/chat', {
      model,
      // messages: [{ role: 'user', content: message }],
      messages,
      stream: false
    })
    return response.data
  }
}